<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="设置名称" prop="settingName">
        <el-input v-model="form.settingName" placeholder="请输入设置名称" />
      </el-form-item>
      <el-form-item label="内容">
        <editor v-model="form.content" :min-height="192"/>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="form.type" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model="form.sort" placeholder="请输入任务名称" />
      </el-form-item>
      <el-form-item label="备注信息" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <!--        <el-form-item label="是否删除" prop="delFlag">-->
      <!--          <el-input v-model="form.delFlag" placeholder="请输入是否删除" />-->
      <!--        </el-form-item>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" style="margin-left: 550px">确 定</el-button>
      <el-button @click="cancel" style="margin-left: 20px">取 消</el-button>
    </div>
  </div>
</template>

<script>
import {getSetting, updateSetting} from "@/api/scp/setting";
export default {
  name: "edit",
  data(){
    return{
      form:{},
      rules:{
        settingName: [
          { required: true, message: '请输入设置名称', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择类型', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: 'blur' }
        ],
        sort: [
          { required: true, message: '请输入排序', trigger: 'blur' }
        ]
      },
      //类型选择项
      options: [{
        value: '客服热线',
        label: '客服热线'
      }, {
        value: '关于我们',
        label: '关于我们'
      }, {
        value: '在线客服',
        label: '在线客服'
      }]
    }
  },
  created() {
    var settingId = this.$route.query.settingId;
    this.init(settingId)
  },
  methods:{
    init(settingId){
      getSetting(settingId).then(response => {
        this.form = response.data;
      });
    },
    submitForm() {
      updateSetting(this.form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.$router.back();
      })
    },
    cancel() {
      this.$router.back();
    }
  }
}
</script>

<style scoped>

</style>
